<?php

$sSql.=" Order By place,portletOrder Desc";

//echo  $sSql."<br/>";
            $rs=$GLOBALS["conn"]->Execute($sSql);

            while ( !$rs->EOF)  {



                //initialize portlet preferences
                $sSql ="SELECT * FROM `portal_portlet_preferences_names` WHERE `portlet_id`=".$rs->fields["portletId"].";";
                // 	echo $sSql ;
                $rsbis=$GLOBALS["conn"]->Execute($sSql);
                $vars="";
                while (!$rsbis->EOF)  {

                    $vars.="$"."portlet_".$rs->fields["appname"]."_".$rsbis->fields["name"]."=null;  ";

                    $vars.="$"."portlet_".$rs->fields["instanceId"]."_".$rsbis->fields["name"]."=null;  ";

                    //echo "$"."portlet_".$rs->fields["id"]."_".$rsbis->fields["name"]."=\"".$rsbis->fields["value"]."\";";

                    $rsbis->MoveNext();
                }

                
           
                //Load portlet preferences
                $sSql ="SELECT * FROM `portal_portlet_preferences` WHERE `portlet_page_id`=".$rs->fields["instanceId"].";";
             //   echo $sSql."<br/>" ;
                $rsbis=$GLOBALS["conn"]->Execute($sSql);
                // 	$currentPortletId=$rs->fields["id"];
                $vars.="$"."system_PortletId=".$rs->fields["portletId"]."; ";
                $vars.="$"."system_PortletInstanceId=".$rs->fields["instanceId"]."; ";
                $vars.=" $"."system_PortletName='".$rs->fields["appname"]."'; ";
                while (!$rsbis->EOF)  {

                    //eval("$"."portlet_".$rs->fields["appname"]."_".$rsbis->fields["name"]."=\"".$rsbis->fields["value"]."\";");
                    $portletUID="Portlet_".$rs->fields["instanceId"]."_";
                    $vars.="$"."portlet_".$rs->fields["appname"]."_".$rsbis->fields["name"]."=\"".$rsbis->fields["value"]."\";  ";

                    $vars.="$"."portlet_".$rs->fields["instanceId"]."_".$rsbis->fields["name"]."=\"".$rsbis->fields["value"]."\";  ";

                    // echo "$"."portlet_".$rs->fields["id"]."_".$rsbis->fields["name"]."=\"".$rsbis->fields["value"]."\";";

                    $rsbis->MoveNext();
                }





                //	$skin="$"."portlet_".$rs->fields["appname"]."_Skin";
                $div="<div id=\\\"".$rs->fields["place"]."\\\" class=\\\"portalBox\\\">";
                //$layout=str_replace($div,$div."\"; include \"apps/".$rs->fields["appurl"]."/index.php\"; echo \"",$layout); // alternative


                $layout=substr_replace($layout, "\"; ".$vars." if (canView('portal_portletpage',".$rs->fields["instanceId"]."))
{ include \"apps/header.php\";  include \"apps/".$rs->fields["appurl"]."/header.php\"; include \"apps/".$rs->fields["appurl"]."/index.php\"; include \"apps/".$rs->fields["appurl"]."/footer.php\"; include \"apps/footer.php\"; } echo \"", (strpos($layout,$div)+strlen($div)),0);





                $rs->MoveNext();
            }
            
           
            $layout=str_replace("echo \"\";","",$layout);
            $layout="echo \"".$layout."\"; ";
            
            $layout=str_replace("\n","",$layout);
            $layout=str_replace("\r","",$layout);
            
    
        


?>
